package xkp.lesson;

public class SingleInstance {

    private static Object object;

    //调用该方法返回同一个对象
    public static Object getInstance(){
        //此处每一次返回的都是不同的对象
        //并且该对象不能为null
        if(object == null){
            object = new Object();
        }
        return object;
    }

    public static void main(String[] args) {
        Object obj1 = getInstance();
        Object obj2 = getInstance();
        System.out.println(obj1 == obj2);
    }
}
